<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <img src="img/image (1).jpg" alt="" width="200" height="200" id="img">

    <br>
    <button class="prev">上一张</button>
    <button class="next">下一张</button>
    <script>
        //获取事件源 标签
        const img=document.getElementById('img');
        const prev=document.querySelector('.prev');
        const next=document.querySelector('.next');
        var minindex=1,maxindex=4,index=minindex;
        //添加按钮的点击事件
        next.onclick=function(){
            if(index===maxindex){
                index=minindex;
            }
            else{
                index++;
            }
            //
            img.setAttribute('src',`img/image (${index}).jpg`)
        }
        prev.onclick=function(){
            if(index===minindex){
                index=maxindex;
            }
            else{
                index--;
            }
            img.setAttribute('src',`img/image (${index}).jpg`)
        }
    </script>
</body>
</html>